package com.example.controller;


import com.example.common.Result;
import com.example.pojo.Message;
import com.example.pojo.Params;
import com.example.service.MessageService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/message")
public class MessageController {

    @Resource
    private MessageService messageService;



    @PostMapping
    public Result save(@RequestBody Message message) {
        if (message.getId() == null) {
            messageService.add(message);
        } else {
            messageService.update(message);
        }
        return Result.success();
    }

    @GetMapping
    public Result findAll() {
        List<Message> list = messageService.findAll();
        return Result.success(list);
    }

    @GetMapping("/search")
    public Result findBySearch(Params params) {
        PageInfo<Message> info = messageService.findBySearch(params);
        return Result.success(info);
    }

}
